package org.ala.tree.lsm.memtable;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 *
 * @author ala
 * @date 2025年5月26日
 */
public enum MemTableOpEnums {
	ADD((byte)1, "add"),
	UPD((byte)2, "update"),
	DEL((byte)3, "del")
	;
	private byte val;
	private String code;
	private MemTableOpEnums(byte val, String code) {
		this.val = val;
		this.code = code;
	}

	
	static Map<Byte, MemTableOpEnums> valMapper = null;
	public static MemTableOpEnums getVal(byte val) {
		if (valMapper == null) {
			synchronized (MemTableOpEnums.class) {
				if (valMapper == null) {
					valMapper = Arrays.stream(values()).collect(Collectors.toMap(e -> e.getVal(), e -> e, (o,n) -> n));
				}
			}
		}
		return valMapper.get(val);
	}
	
	
	public byte getVal() {
		return val;
	}
	public void setVal(byte val) {
		this.val = val;
	}
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	
}
